package E2020;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPClient {
    public static void main(String[] args) {
        DatagramSocket receiver = null;
        DatagramPacket packet = null;
        try {
            receiver = new DatagramSocket(8888);

            byte[] buf = new byte[1024];
            packet = new DatagramPacket(buf,buf.length);

            System.out.println("接收端等待接收信息中....");
            while (true){
                receiver.receive(packet);
                String str = new String(packet.getData(),0,packet.getLength());
                System.out.println(packet.getAddress()+":"+packet.getPort()+"发来了消息---"+str);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
